<template>
  <div>
    <!-- 隐藏的输入框 -->
    <el-dialog title="举报" :visible.sync="dialogFormVisible">
      <div>违反法律法规</div>
      <br>
      <el-radio v-model="radio" label="违法违规">违法违规</el-radio>
      <el-radio v-model="radio" label="诈骗">诈骗</el-radio>
      <el-radio v-model="radio" label="赌博">赌博</el-radio>
      <el-radio v-model="radio" label="低俗">低俗</el-radio>
      <br>
      <br>
      <div>侵犯个人权益</div>
      <br>
      <el-radio v-model="radio" label="人身攻击">人身攻击</el-radio>
      <el-radio v-model="radio" label="泄露隐私">泄露隐私</el-radio>
      <br>
      <br>
      <div>有害社区环境</div>
      <br>
      <el-radio v-model="radio" label="垃圾广告">垃圾广告</el-radio>
      <el-radio v-model="radio" label="刷屏">刷屏</el-radio>
      <el-radio v-model="radio" label="内容不相干">内容不相干</el-radio>
      <el-radio v-model="radio" label="引战">引战</el-radio>
      <br>
      <br>
      <el-radio v-model="radio" label="其他">其他</el-radio>
      
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="report"
          >提交</el-button
        >
      </div>
    </el-dialog>
    <el-card class="reply">
      <div class="textbox">
        <el-input
          class="inp"
          type="textarea"
          placeholder="说句什么吧"
          v-model="input"
          @input="change($event)"
          :rows="4"
        >
        </el-input>
        <el-button type="primary" round class="btn" @click="addbtn()"
          >确定</el-button
        >
      </div>
      <!-- 一级评论 -->
      <div class="com" v-for="(item, index) in pllist" :key="index">
        <img :src="basurl + item.imgs" alt="图片" />
        <div class="text">
          <span class="name">{{ item.username }}</span
          ><span class="time">{{ item.time }}</span>
          <p>{{ item.content }}</p>
          <span class="hui" @click="huifu(item.id)">举报</span>
          <i
            class="fa fa-thumbs-up icon"
            aria-hidden="true"
            @click="zan(index, item.id)"
            ref="icon"
          ></i>
          <span class="num">{{ item.love }}</span>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getpl, inserpl, updatezan,jvbao } from "@/api/userone";
export default {
  data() {
    return {
      input: "",
      //input2: "",
      hid: false,
      dialogFormVisible: false,
      ison: null,
      pllist: [],
      show: false,
      basurl: "http://127.0.0.1:7001",
      islove: 1,
      radio:"",
      id:"",
    };
  },
  created() {
    this.getdata();
  },
  methods: {
    //按钮
    addbtn() {
      if (sessionStorage.getItem("userid")) {
        this.addpl();
      } else {
        this.open();
      }
    },
    //获取评论信息
    getdata() {
      getpl(
        sessionStorage.getItem("id"),
        sessionStorage.getItem("userid")
      ).then((res) => {
        if (res.code == 0) {
          this.pllist = res.data;
        }
      });
    },
    //添加评论
    addpl() {
      inserpl(
        this.input,
        sessionStorage.getItem("id"),
        sessionStorage.getItem("userid")
      ).then((res) => {
        if (res.code == 0) {
          this.open2();
          this.getdata();
          this.input = "";
        } else {
          this.open4();
        }
      });
    },
    //举报
    report(){
      jvbao(this.id,this.radio).then(res =>{
        if (res.code == 0) {
          this.open1();
         this.dialogFormVisible = false;
        }
      })
    },
    change() {
      this.$forceUpdate();
    },
    huifu(id) {
      this.id = id;
      this.dialogFormVisible = true;
    },
    //点赞数
    zan(index, id) {
      if (this.islove) {
        this.$refs.icon[index].style.color = "#1e7dd7";
        updatezan(id, this.islove).then((res) => {
          if (res.code == 0) {
            this.getdata();
          } else {
            alert("失败");
          }
        });
        this.islove = 0;
      } else {
        this.$refs.icon[index].style.color = "#303133";
        updatezan(id, this.islove).then((res) => {
          if (res.code == 0) {
            this.getdata();
          } else {
            alert("失败");
          }
        });
        this.islove = 1;
      }
    },
    erzan(index) {
      this.$refs.erzan[index].style.color = "#1e7dd7";
    },
    //消息提示
    open2() {
      this.$message({
        showClose: true,
        message: "发表评论成功",
        type: "success",
      });
    },
    open1() {
      this.$message({
        showClose: true,
        message: "举报成功",
        type: "success",
      });
    },
    open4() {
      this.$message({
        showClose: true,
        message: "发表评论失败，请稍后再评论",
        type: "error",
      });
    },
    open() {
      this.$alert("请先登录后再评论哦", "提示", {
        confirmButtonText: "确定",
        callback: (action) => {
          this.$message({
            type: "info",
            message: `action: ${action}`,
          });
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.reply {
  width: 1200px;
  margin: 0 auto;
  .inp {
    width: 800px;
  }
  .btn {
    margin-left: 20px;
  }
  .com {
    display: flex;
    margin-top: 20px;
    margin-bottom: 20px;
    img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }
    .text {
      margin-left: 10px;
      .name {
        font-size: 20px;
        color: #303133;
      }
      .time {
        color: #909399;
        margin-left: 20px;
      }
      p {
        font-size: 18px;
        color: #303133;
        margin-top: 20px;
      }
      .icon {
        margin-left: 700px;
        font-size: 25px;
        cursor: pointer;
        transform: translateY(-8px);
      }
      .hui {
        color: #1e7dd7;
        cursor: pointer;
      }
      .num {
        color: #909399;
        display: inline-block;
        transform: translateY(-8px);
      }
    }
  }
}
.iconn {
  margin-left: 639px;
  font-size: 25px;
  cursor: pointer;
  transform: translateY(-8px);
}
</style>